package com.seedwill.common.persistence;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import com.seedwill.common.model.TreeSchema;

/**
 * 过滤器容器
 * 
 * @author kdyi
 *
 */
public class FilterContainer implements java.io.Serializable, Cloneable{

	/**
	 * 
	 */
	private static final long serialVersionUID = -8883752411590325717L;
	/**
	 * 是否分页
	 */
	private boolean pagnation;
	
	public boolean isPagnation() {
		return pagnation;
	}

	public void setPagnation(boolean pagnation) {
		this.pagnation = pagnation;
	}

	/**
	 * 过滤器LIST
	 */
	private List<Filter> filterList;

	public List<Filter> getFilterList() {
		prepareFilterList();
		return filterList;
	}

	public void setFilterList(List<Filter> filterList) {
		this.filterList = filterList;
	}
	
	public void addFilter(Filter f){
		prepareFilterList();
		filterList.add(f);
	}

	private void prepareFilterList() {
		if(null == filterList){
			filterList = new ArrayList<Filter>();
		}
	}
	
	/**
	 * 每页记录数目
	 */
	private int pageSize;
	
	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	/**
	 * pagnation为TRUE的时候请求的页码
	 */
	private int requestPageNo;
	
	public int getRequestPageNo() {
		return requestPageNo;
	}

	public void setRequestPageNo(int requestPageNo) {
		this.requestPageNo = requestPageNo;
	}

	/**
	 * 实体类别
	 */
	private Class entityClz;

	public Class getEntityClz() {
		return entityClz;
	}

	public void setEntityClz(Class entityClz) {
		this.entityClz = entityClz;
	}
	
	private String entityType;
	
	public String getEntityType() {
		return entityType;
	}

	public void setEntityType(String entityType) {
		this.entityType = entityType;
	}
	
	/**
	 * 是否为树
	 */
	private boolean asTree;
 
	public boolean isAsTree() {
		return asTree;
	}

	public void setAsTree(boolean asTree) {
		this.asTree = asTree;
	}
	
	private TreeSchema treeSchema;

	public TreeSchema getTreeSchema() {
		return treeSchema;
	}

	public void setTreeSchema(TreeSchema treeSchema) {
		this.treeSchema = treeSchema;
	}
	
	/**
	 * 懶加载
	 */
	private boolean asLazyFetchChildren;

	public boolean isAsLazyFetchChildren() {
		return asLazyFetchChildren;
	}

	public void setAsLazyFetchChildren(boolean asLazyFetchChildren) {
		this.asLazyFetchChildren = asLazyFetchChildren;
	}

	/**
	 * 排序
	 */
	private List<OrderBy> orderByList;
	
	public List<OrderBy> getOrderByList() {
		return orderByList;
	}

	public void setOrderByList(List<OrderBy> orderByList) {
		this.orderByList = orderByList;
	}

	/**
	 * 
	 */
	private void prepareOrderByList() {
		if(null == orderByList){
			orderByList = new ArrayList<OrderBy>();
		}
	}
	
	/**
	 * @param f
	 */
	public void addFilter(OrderBy f){
		prepareOrderByList();
		orderByList.add(f);
	}

 
    public Object clone() {
    	try {
    		FilterContainer v = (FilterContainer) super.clone();
    		v.asLazyFetchChildren = this.asLazyFetchChildren;
    		v.asTree = this.asTree;
    		v.entityClz = this.entityClz;
    		v.entityType = this.entityType;
    		v.filterList = this.filterList;
    		v.orderByList = this.orderByList;
    		v.pageSize = this.pageSize;
    		v.pagnation = this.pagnation;
    		v.requestPageNo = this.requestPageNo;
    		v.treeSchema = this.treeSchema;
    	    return v;
    	} catch (CloneNotSupportedException e) {
    	    // this shouldn't happen, since we are Cloneable
    	    throw new InternalError();
    	}
   }

}
